package cc.autoapi.pucong.auto.flow.provider.aop.controller;

import cc.autoapi.pucong.auto.flow.core.root.entity.BatchDeleteIdDto;
import cc.autoapi.pucong.auto.flow.core.root.exception.AutoFlowBaseController;
import cc.autoapi.pucong.auto.flow.core.root.exception.AutoFlowExceptionHandler;
import cc.autoapi.pucong.auto.flow.core.root.utils.Res;
import cc.autoapi.pucong.auto.flow.provider.aop.entity.dto.*;
import cc.autoapi.pucong.auto.flow.provider.aop.entity.vo.ProjectAopFitterApiVo;
import cc.autoapi.pucong.auto.flow.provider.aop.entity.vo.ProjectAopInfoVo;
import cc.autoapi.pucong.auto.flow.provider.aop.manager.AopInfoManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author pucong
 * @url https://gitee.com/pucong
 * @create 2023-11-21
 */
@RestController
@RequestMapping("/aopInfo")
public class ProjectAopInfoController extends AutoFlowBaseController implements AutoFlowExceptionHandler {

    @Autowired
    private AopInfoManager aopInfoManager;

    @GetMapping("/getProjectAopInfoList")
    public Res<List<ProjectAopInfoVo>> getProjectAopInfoList(ProjectAopInfoSelectDto projectAopInfoSelectDto) {
        List<ProjectAopInfoVo> projectAopInfoList = aopInfoManager.getProjectAopInfoList(projectAopInfoSelectDto);
        return Res.ok(projectAopInfoList);
    }

    @GetMapping("/getProjectAopInfoById/{id}")
    public Res<ProjectAopInfoVo> getProjectAopInfoById(@PathVariable("id") String id) {
        ProjectAopInfoVo vo = aopInfoManager.getProjectAopInfoById(id);
        return Res.ok(vo);
    }

    @PostMapping("/insertProjectAopInfo")
    public Res<Integer> insertProjectAopInfo(@Validated @RequestBody ProjectAopInfoInsertDto dto) {
        int i = aopInfoManager.insertProjectAopInfo(dto);
        return Res.ok(i);
    }

    @PutMapping("/updateProjectAopInfoById/{id}")
    public Res<Integer> updateProjectAopInfoById(@PathVariable("id") String id, @Validated @RequestBody ProjectAopInfoUpdateDto dto) {
        int i = aopInfoManager.updateProjectAopInfoById(id, dto);
        return Res.ok(i);
    }

    @PostMapping("/startProjectAopByAopId/{aopId}")
    public Res<Integer> startProjectAopById(@PathVariable("aopId") String aopId) {
        int i = aopInfoManager.startProjectAopByAopId(aopId);
        return Res.ok(i);
    }

    @PostMapping("/stopProjectAopByAopId/{aopId}")
    public Res<Integer> stopProjectAopById(@PathVariable("aopId") String aopId) {
        int i = aopInfoManager.stopProjectAopByAopId(aopId);
        return Res.ok(i);
    }

    /**
     * 根据主键获取符合规则的服务
     *
     * @param aopId
     * @return
     */
    @GetMapping("/getFitterApiTreeByAopId/{aopId}")
    public Res<List<ProjectAopFitterApiVo>> getFitterApiTreeByAopId(@PathVariable("aopId") String aopId) {
        List<ProjectAopFitterApiVo> vos = aopInfoManager.getFitterApiTreeByAopId(aopId);
        return Res.ok(vos);
    }

    @DeleteMapping("/batchDeleteProjectAopInfoByIds")
    public Res<Integer> batchDeleteProjectAopInfoByIds(BatchDeleteIdDto dto) {
        int i = aopInfoManager.batchDeleteProjectAopInfoByIds(dto.getIdList());
        return Res.ok(i);
    }
}